/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * DialogDetailUser.java
 *
 * Created on 13 Nov 12, 12:36:40
 */
package sistemperpustakaan.view.user;

import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import sistemperpustakaan.controller.UserController;
import sistemperpustakaan.utility.UserUtility;

/**
 *
 * @author EKo
 */
public class DialogDetailUser extends javax.swing.JDialog {

    UserController controller;
    boolean isNew = false;

    /** Creates new form DialogDetailUser */
    public DialogDetailUser(java.awt.Frame parent, boolean modal, UserController controller) {
        super(parent, modal);
        this.controller = controller;
        initComponents();
        controller.setDetailUser(this);
        setLocationRelativeTo(controller.getTypeUserView());
        isNew = true;
        setTitle("Tambah User");
        setButton();
        buttonSave.setEnabled(UserUtility.privilege[UserUtility.INSERT_UPDATE_DELETE]);
    }

    public DialogDetailUser(java.awt.Frame parent, boolean modal, UserController controller, String username) {
        super(parent, modal);
        this.controller = controller;
        initComponents();
        setLocationRelativeTo(controller.getTypeUserView());
        controller.setDetailUser(this);
        controller.showDetailUser(username);
        isNew=false;
        setTitle("Detail User");
        setButton();
        buttonSave.setEnabled(UserUtility.privilege[UserUtility.INSERT_UPDATE_DELETE]);
    }

    public JTextField getTxtIdType() {
        return txtIdType;
    }

    public void setTxtIdType(JTextField txtIdType) {
        this.txtIdType = txtIdType;
    }

    public JTextField getTxtNamaType() {
        return txtNamaType;
    }

    public void setTxtNamaType(JTextField txtNamaType) {
        this.txtNamaType = txtNamaType;
    }

    public JTextField getTxtNamaUser() {
        return txtNamaUser;
    }

    public void setTxtNamaUser(JTextField txtNamaUser) {
        this.txtNamaUser = txtNamaUser;
    }

    public JPasswordField getTxtPassword() {
        return txtPassword;
    }

    public void setTxtPassword(JPasswordField txtPassword) {
        this.txtPassword = txtPassword;
    }

    public JTextField getTxtUserId() {
        return txtUserId;
    }

    public void setTxtUserId(JTextField txtUserId) {
        this.txtUserId = txtUserId;
    }

    public boolean isIsNew() {
        return isNew;
    }

    public void setIsNew(boolean isNew) {
        this.isNew = isNew;
    }

    

    private void setButton() {
        buttonCancel.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                dispose();
            }
        });

        buttonSave.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                if (isNew) {
                    controller.saveNewUser();
                } else {
                    controller.saveUpdateUser();
                }
            }
        });
        buttonSelectType.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                SelectTypeUser tu = new SelectTypeUser(controller.getUserView().getFrameMain(), true, controller);
                Point p = txtIdType.getLocationOnScreen();
                p.setLocation(p.getX(), p.getY()+28);
                tu.setLocation(p);
                tu.setVisible(true);
            }
        });
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel15 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        txtPassword = new javax.swing.JPasswordField();
        jLabel19 = new javax.swing.JLabel();
        txtNamaUser = new javax.swing.JTextField();
        txtIdType = new javax.swing.JTextField();
        buttonSelectType = new javax.swing.JButton();
        txtNamaType = new javax.swing.JTextField();
        txtUserId = new javax.swing.JTextField();
        gbr = new javax.swing.JLabel();
        buttonSave = new javax.swing.JButton();
        buttonCancel = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel15.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jLabel15.setText("Username");
        jPanel1.add(jLabel15, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 14, 103, -1));

        jLabel17.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jLabel17.setText("Type ID ");
        jPanel1.add(jLabel17, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 46, 103, -1));

        jLabel18.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jLabel18.setText("Password ");
        jPanel1.add(jLabel18, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 74, 103, -1));
        jPanel1.add(txtPassword, new org.netbeans.lib.awtextra.AbsoluteConstraints(117, 71, 236, -1));

        jLabel19.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jLabel19.setText("Nama User");
        jPanel1.add(jLabel19, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 105, 103, -1));
        jPanel1.add(txtNamaUser, new org.netbeans.lib.awtextra.AbsoluteConstraints(117, 102, 236, -1));

        txtIdType.setEditable(false);
        jPanel1.add(txtIdType, new org.netbeans.lib.awtextra.AbsoluteConstraints(117, 43, 39, -1));

        buttonSelectType.setText("...");
        jPanel1.add(buttonSelectType, new org.netbeans.lib.awtextra.AbsoluteConstraints(310, 42, 38, -1));
        jPanel1.add(txtNamaType, new org.netbeans.lib.awtextra.AbsoluteConstraints(162, 43, 142, -1));
        txtNamaType.setEditable(false);
        jPanel1.add(txtUserId, new org.netbeans.lib.awtextra.AbsoluteConstraints(117, 11, 231, -1));

        gbr.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        gbr.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sistemperpustakaan/image/user.png"))); // NOI18N

        buttonSave.setText("Save");

        buttonCancel.setText("Cancel");

        jLabel6.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jLabel6.setText("Detail User");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 386, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(28, 28, 28)
                        .addComponent(buttonSave, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(buttonCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 194, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(148, 148, 148)
                    .addComponent(gbr, javax.swing.GroupLayout.PREFERRED_SIZE, 248, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 65, Short.MAX_VALUE)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(buttonCancel)
                    .addComponent(buttonSave))
                .addContainerGap())
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addComponent(gbr)
                    .addContainerGap(28, Short.MAX_VALUE)))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    /**
     * @param args the command line arguments
     */
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton buttonCancel;
    private javax.swing.JButton buttonSave;
    private javax.swing.JButton buttonSelectType;
    private javax.swing.JLabel gbr;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JTextField txtIdType;
    private javax.swing.JTextField txtNamaType;
    private javax.swing.JTextField txtNamaUser;
    private javax.swing.JPasswordField txtPassword;
    private javax.swing.JTextField txtUserId;
    // End of variables declaration//GEN-END:variables
}
